
let fs = require("fs");
let jsonformt = require("json-format")
let cn = require("./Localization_jz.js")
let poisPath = "C:/Program Files (x86)/scott/steamapps/common/7 Days To Die/Data/Prefabs/POIs";

let files = fs.readdirSync(poisPath);


let buildData = {};

files.forEach(f => {
    if(/^(.+)\.xml$/.test(f)) {
        let bid = RegExp.$1;
        buildData[bid] = {
            name: cn[bid]?.cn || bid,
            en: cn[bid]?.en || bid,
        }
        let str = fs.readFileSync(poisPath + "/" + f).toString();

        if(/<property name="DifficultyTier" value="(\d+)" \/>/.test(str)) {
            buildData[bid].dif = RegExp.$1;
            if(buildData[bid].dif >= 5) {
                console.log(buildData[bid]);
            }
        }


    }
});


files.forEach(f => {
    if(/^(.+)\.jpg$/.test(f)) {
        let bid = RegExp.$1;
        if(buildData[bid]){
            buildData[bid].jpg = poisPath+ "/"+f
        }
    }
})
fs.writeFileSync("./builds.json", jsonformt(buildData, undefined, 4));




// let fs = require("fs");
let copyimgerr = []

for (let key in bs) {
	// if(bs[key].dif >= 5 ) {
		console.log(bs[key]);
		if(bs[key].jpg) {
			analysis(bs[key])
		}
	// }
}





function analysis(data) {
	if(data.dif) {
		if(!fs.existsSync("../builds/" + data.dif)){
			fs.mkdirSync("../builds/"+data.dif)
		}
		let dirname = "../builds/" + data.dif + "/" + replaceSpe2(data.name + "__" + data.en)
		if(!fs.existsSync(dirname)){
			fs.mkdirSync(dirname)
		}
		try {
			fs.copyFileSync(data.jpg, dirname + "/" + replaceSpe(data.name) + ".jpg")
		} catch (error) {
			copyimgerr.push(data.name)
		}
	}
}

function replaceSpe(str) {
	return str.replace(/[,，。；‘“’”"']| /ig, "_")
}

function replaceSpe2(str) {
	return str.replace(/[.,，。；‘“’”"']| /ig, "_")
}
